package com.woniuxy.member.app.apiImpl.util;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import utils.Assert;

import javax.servlet.http.HttpServletRequest;

@Slf4j
public class RequestUtil {

    public static Integer getStoreId() {
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        String storeId = request.getHeader("storeId");
        Assert.state(storeId!=null,"用户未登录");
        log.info("从token获取到的storeId:{}",storeId);
        return Integer.valueOf(storeId);
    }

    public static Integer getMemberId() {
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        String memberId = request.getHeader("memberId");
        Assert.state(memberId!=null,"用户未登录");
        log.info("从token获取到的memberId:{}",memberId);
        return Integer.valueOf(memberId);
    }

    public static Integer getTableId() {
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        String tableId = request.getHeader("tableId");
        Assert.state(tableId!=null,"用户未登录");
        log.info("从token获取到的tableId:{}",tableId);
        return Integer.valueOf(tableId);
    }
}
